<template>
    <div class="mod-admin__education">
        <div class="top-search">
            <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()" label-position="top">
                <div class="top-search_form">
                    <div class="top-search_form_input">
                        <el-form-item :label="$t('spices.categoryName')">
                            <el-input v-model="state.dataForm.name" :placeholder="$t('input')"
                                clearable></el-input>
                        </el-form-item>
                    </div>
                    <div class="top-search_form_btn">
                        <el-form-item>
                            <el-button @click="state.getDataList()">{{ $t("reset") }}</el-button>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="state.getDataList()">{{ $t("query") }}</el-button>
                        </el-form-item>
                    </div>
                </div>
            </el-form>
        </div>
        <div class="content">

            <div class="content-btns">
                <el-button v-if="state.hasPermission('sys:user:save')" type="primary" @click="addOrUpdateHandle()">{{
                    $t("add") }}</el-button>
            </div>
            <el-table v-loading="state.dataListLoading" :data="state.dataList" @sort-change="state.dataListSortChangeHandle"
                style="width: 100%;height: calc(100vh - 390px);">
                <el-table-column prop="name" :label="$t('spices.categoryName')" sortable="custom" header-align="center"
                    align="center"></el-table-column>
                    <!-- <el-table-column prop="name" :label="$t('food.categoryParentName')" sortable="custom" header-align="center"
                    align="center"></el-table-column> -->
                <el-table-column prop="sort" :label="$t('spices.sort')" sortable="custom" header-align="center"
                    align="center"></el-table-column>
                <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center">
                    <template v-slot="scope">
                        <el-button v-if="state.hasPermission('sys:user:update')" type="primary" link
                            @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
                        <el-button v-if="state.hasPermission('sys:user:delete')" type="primary" link
                            @click="state.deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit"
                :total="state.total" layout="total, sizes, prev, pager, next, jumper"
                @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle">
            </el-pagination>

        </div>

        <!-- 弹窗, 新增 / 修改 -->
        <add-or-update ref="addOrUpdateRef" @refreshDataList="state.getDataList"></add-or-update>
    </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { reactive, ref, toRefs, onMounted } from "vue";
import AddOrUpdate from "./spicesCategory-add-or-update.vue";
import { ElMessageBox, ElMessage } from 'element-plus';
import { useI18n } from 'vue-i18n'
import baseService from "@/service/baseService";
const { t } = useI18n();

const view = reactive({
    getDataListURL: "/edu/diet/condiment/class/page",
    getDataListIsPage: true,
    deleteURL: "/edu/diet/condiment/class/delete",
    deleteIsBatch: true,
    dataForm: {
        name: ""
    },
});

const state = reactive({ ...useView(view), ...toRefs(view) });

const addOrUpdateRef = ref();
const addOrUpdateHandle = (id?: number) => {
    addOrUpdateRef.value.init(id);
};

const treeRef = ref()

</script>
